/**
 * 
 */
package com.xy.frame.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.xy.commons.PageUtil;
import com.xy.frame.dao.LoginMapper;

/**
 * @author admin
 * 
 */
@Service
public class LoginService {
	@Autowired
	LoginMapper loginMapper;

	/**
	 * 验证用户登录
	 * 
	 * @param loginName
	 * @param passwd
	 * @return
	 */
	public Map<String, Object> loginCheck(String loginName, String passwd) {
		Map<String, Object> p = Maps.newHashMap();
		p.put("loginName", loginName);
		List<Map<String, Object>> userInfo = loginMapper.loginCheck(p);
		if (userInfo != null && userInfo.size() > 0) {
			// 密码 客户端加密
			if (passwd.equals(userInfo.get(0).get("F_LOGIN_PWD"))) {
				return userInfo.get(0);
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 分页查询用户
	 * 
	 * @param params
	 *            查询参数
	 * @return
	 */
	public Map<String, Object> queryUserList(Map<String, Object> params) {
		List<Map<String, Object>> items = loginMapper.queryUserList(params);
		int count = loginMapper.queryUserCount(params);
		Map<String, Object> pages = Maps.newHashMap();
		pages.put(PageUtil.ITEMS, items);
		pages.put(PageUtil.TOTALS, count);
		return pages;
	}
}
